package it.nextgo.BusMate.task;

import it.nextgo.BusMate.model.Linea;

import java.io.InputStream;

import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;

public class SfogliaTask extends AsyncTask<Void, Void, Linea[]> {

	Context context;
	ConnectivityManager con;
	NetworkInfo net;

	public SfogliaTask(Context applicationContext) {
		context=applicationContext;
		con = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		net = con.getActiveNetworkInfo();
	}

	@Override
	protected Linea[] doInBackground(Void... params) {
		if (net != null && net.isConnectedOrConnecting()) {
			RestTemplate restTemplate = new RestTemplate();

			restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());

			Linea[] pro = restTemplate.getForObject("http://busmatedev.appspot.com/getLinee", Linea[].class);
			return pro;
		}
		return null;
	}
}
